package com.chimbori.crux.plugins

import com.chimbori.crux.api.Rewriter
import okhttp3.HttpUrl

public class TrackingParameterRemover(private val trackingParameters: Array<String> = TRACKING_PARAMETERS) : Rewriter {
  override fun rewrite(url: HttpUrl): HttpUrl = url.newBuilder().apply {
    url.queryParameterNames.filter { it in trackingParameters }.forEach {
      removeAllQueryParameters(it)
    }
  }.build()

  public companion object {
    public val TRACKING_PARAMETERS: Array<String> = arrayOf(
      "__hsfp",
      "__hssc",
      "__hstc",
      "__s",
      "_hsenc",
      "_hsmi",
      "_openstat",
      "action_object_map",
      "action_ref_map",
      "action_type_map",
      "cvid",
      "dclid",
      "fb_action_ids",
      "fb_action_types",
      "fb_ref",
      "fb_source",
      "fbclid",
      "ga_campaign",
      "ga_content",
      "ga_medium",
      "ga_place",
      "ga_source",
      "ga_term",
      "gbraid",
      "gclid",
      "gs_l",
      "hsa_acc",
      "hsa_ad",
      "hsa_cam",
      "hsa_grp",
      "hsa_kw",
      "hsa_mt",
      "hsa_net",
      "hsa_src",
      "hsa_tgt",
      "hsa_ver",
      "hsCtaTracking",
      "ICID",
      "igshid",
      "mc_cid",
      "mc_eid",
      "mkt_tok",
      "ml_subscriber",
      "ml_subscriber_hash",
      "msclkid",
      "oicd",
      "oly_anon_id",
      "oly_enc_id",
      "otc",
      "rb_clickid",
      "s_cid",
      "soc_src",
      "soc_trk",
      "stm_campaign",
      "stm_cid",
      "stm_content",
      "stm_medium",
      "stm_name",
      "stm_reader",
      "stm_referrer",
      "stm_social",
      "stm_social-type",
      "stm_source",
      "stm_term",
      "twclid",
      "utm_brand",
      "utm_campaign",
      "utm_cid",
      "utm_content",
      "utm_id",
      "utm_medium",
      "utm_name",
      "utm_place",
      "utm_pubreferrer",
      "utm_reader",
      "utm_referrer",
      "utm_social",
      "utm_social-type",
      "utm_source",
      "utm_swu",
      "utm_term",
      "utm_userid",
      "utm_viz_id",
      "vero_conv",
      "vero_id",
      "wbraid",
      "wickedid",
      "yclid",
    )
  }
}
